/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.admin.candidate;

import hibernate.dao.StaffDAO;
import hibernate.dao.StudentDAO;
import hibernate.entity.Staffs;
import hibernate.entity.Students;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import ui.admin.AbstractAdminBean;

/**
 *
 * @author Admin
 */
@ManagedBean
@RequestScoped
public class Candidate extends AbstractAdminBean {

    /**
     * Creates a new instance of Candidate
     */
    List<Students> listStu;
    List<Staffs> listStaff;
    StudentDAO stuDao = new StudentDAO();
    StaffDAO staffDao = new StaffDAO();
    int mode = 2;

    public List<Students> getListStu() {
        return listStu;
    }

    public void setListStu(List<Students> listStu) {
        this.listStu = listStu;
    }

    public List<Staffs> getListStaff() {
        return listStaff;
    }

    public void setListStaff(List<Staffs> listStaff) {
        this.listStaff = listStaff;
    }

    public int getMode() {
        return mode;
    }

    public void setMode(int mode) {
        this.mode = mode;
    }

    public Candidate() {
        isAuthor();
        loadData();
    }

    void loadData() {
        listStu = stuDao.readByStatus(0);
        listStaff = staffDao.readByStatus(0);
    }

    /**
     * @param id an id for accept staff/student's update
     * @return String
     * @see list page
     */
    public String accept(int id) {
        switch (mode) {
            case 2:
                Staffs s = staffDao.readByID(id);
                s.setStatus(2);
                staffDao.update(s);
                break;
            case 3:
                Students s1 = stuDao.readByID(id);
                s1.setStatus(2);
                stuDao.update(s1);
                break;
        }
        loadData();
        return "list";
    }
}
